import { h, ref } from 'vue';
import { NAvatar, NImage, NTag, NSwitch, NRate } from 'naive-ui';
import { cloneDeep } from 'lodash-es';
import { FormSchema } from '@/components/Form';
import { Dicts } from '@/api/dict/dict';

import { isArray, isNullObject } from '@/utils/is';
import { getFileExt } from '@/utils/urlUtils';
import { defRangeShortcuts, defShortcuts, formatToDate } from '@/utils/dateUtil';
import { validate } from '@/utils/validateUtil';
import { getOptionLabel, getOptionTag, Option, Options, errorImg } from '@/utils/hotgo';

export class State {
  public id = 0; // id
  public code = ''; // 代码
  public name = ''; // 名字
  public lastPrice = null; // 最新价
  public changePercent = null; // 涨跌幅
  public changeAmount = null; // 涨跌额
  public volume = null; // 成交量
  public turnover = null; // 成交额
  public amplitude = null; // 振幅
  public high = null; // 最高
  public low = null; // 最低
  public open = null; // 开盘价
  public closed = null; // 收盘价
  public volumeRatio = null; // 量比
  public yesterdayClosed = null; // 昨收
  public date = ''; // 日期

  constructor(state?: Partial<State>) {
    if (state) {
      Object.assign(this, state);
    }
  }}

export function newState(state: State | Record<string, any> | null): State {
  if (state !== null) {
    if (state instanceof State) {
      return cloneDeep(state);
    }
    return new State(state);
  }
  return new State();
}



export const rules = {
  code: {
    required: true,
    trigger: ['blur', 'input'],
    type: 'string',
    message: '请输入代码',
  },
};

export const schemas = ref<FormSchema[]>([
  {
    field: 'id',
    component: 'NInputNumber',
    label: 'id',
    componentProps: {
      placeholder: '请输入id',
      onUpdateValue: (e: any) => {
        console.log(e);
      },
    },
  },
]);

export const columns = [
  {
    title: 'id',
    key: 'id',
  },
  {
    title: '代码',
    key: 'code',
  },
  {
    title: '名字',
    key: 'name',
  },
  {
    title: '最新价',
    key: 'lastPrice',
  },
  {
    title: '涨跌幅',
    key: 'changePercent',
  },
  {
    title: '涨跌额',
    key: 'changeAmount',
  },
  {
    title: '成交量',
    key: 'volume',
  },
  {
    title: '成交额',
    key: 'turnover',
  },
  {
    title: '振幅',
    key: 'amplitude',
  },
  {
    title: '最高',
    key: 'high',
  },
  {
    title: '最低',
    key: 'low',
  },
  {
    title: '开盘价',
    key: 'open',
  },
  {
    title: '收盘价',
    key: 'closed',
  },
  {
    title: '量比',
    key: 'volumeRatio',
  },
  {
    title: '昨收',
    key: 'yesterdayClosed',
  },
  {
    title: '日期',
    key: 'date',
    render(row) {
      return formatToDate(row.date);
    },
  },
];